user = {"root": 123456, "wy": 123}
user1 = ["root"]
user2 = ["wy", {"姓名": "wy", "密码": 123, "爱好": "football"}]


def user5():
    while 1:
        print("你是普通用户，输入1编辑爱好，输入2返回上级菜单")
        b = input()
        if int(b) == 1:
            print("你可以开始修改爱好了！")
            userinter = input("输入你的爱好：")
            c = user2.index(m) + 1
            user2[c]["爱好"] = userinter
            print("姓名：{姓名}，密码：{密码}，爱好：{爱好}".format(**user2[c]))
            print("修改成功")
        else:
            break


def Root():
    while 1:
        print("你是管理员：输入1添加用户，输入2删除用户，输入3修改用户，输入4查看用户,其他数返回上一级")
        c = input()
        if int(c) == 1:
            add()
        elif int(c) == 2:
            delete()
        elif int(c) == 3:
            amend()
        elif int(c) == 4:
            check1()
        else:
            break


def add():
    while 1:
        a = input("请输入1继续，2返回上级页面:")
        if a == '1':
            b = input("输入1添加普通用户，输入2添加管理员:")
            if b == "1":
                name2 = input("请输入用户姓名:")
                c = 0
                for i in user2:
                    if name2 == i:
                        print("不能添加已有用户")
                        c == 1
                        break
                if c == 0:
                    pwd1 = input("请输入密码:")
                    like1 = input("请输入爱好:")
                    user[name2] = pwd1
                    user2.append(name2)
                    name3 = {"姓名": name2, "密码": pwd1, "爱好": like1}
                    user2.append(name3)
                    print("添加成功")
            elif b == "2":
                name1 = input("请输入用户姓名:")
                c = 0
                for d in user1:
                    if name1 == d:
                        print("不能添加已有用户")
                        c = 1
                        break
                if c == 0:
                    pwd2 = input("请输入密码:")
                    user[name1] = int(pwd2)
                    user1.append(name1)
                    print("添加成功")
            else:
                print("输入不合法")
        elif a == '2':
            break
        else:
            print("输入不合法")


def delete():
    while 1:
        a = input("请输入1删除用户（只能删除普通用户），2返回上级页面：")
        if a == "1":
            name5 = input("请输入你想删除的用户名")
            for i in user1:
                if i == name5:
                    c = user2.index(i)
                    del user2[c]
                    del user2[c + 1]
                    break
                else:
                    print("用户名不存在")
                    break
        else:
            break


def amend():
    while 1:
        a = input("请输入1修改用户（只能删除普通用户），2返回上级页面：")
        if a == "1":
            b = input("请输入想要修改的用户名：")
            for i in user2:
                if b == 1:
                    c = user2.index(b) + 1
                    print(user2[c])
                    d = input("输入1修改密码，输入2修改爱好（姓名不能修改）,输入其他返回：")
                    if d == "1":
                        e = input("请输入新密码：")
                        user2[c]["密码"] = e
                        break
                    elif d == "2":
                        r = input("请输入爱好：")
                        user2[c]["爱好"] = r
                        break
                    else:
                        break
        else:
            break


def check1():
    while 1:
        a = input("请输入1查看用户，2返回上级页面：")
        if a == "1":
            b = input("请输入想要查看用户的用户名（不可查看普通用户）：")
            for i in user2:
                if b == i:
                    c = user2.index(i) + 1
                    print(user2[c])
        else:
            break


def main1():
    while 1:
        a = input("输入1登录普通用户，输入2登录管理员用户，输入任意其他数，退出：")
        c = 0
        if a == "2":
            username = input("账号：")
            for n in user1:
                if username == n:
                    pwd = input("密码：")
                    c = 1
                    if int(pwd) == user[username]:
                        print("管理员登录成功")
                        Root()
                        break
                    else:
                        print("密码错误")
            if c == 0:
                print("账号错误")
        elif a == "1":
            username = input("账号：")
            global m
            m = username
            for key in user2:
                if username == key:
                    pwd = input("密码：")
                    c = 1
                    if int(pwd) == user[username]:
                        print("用户登录成功")
                        user5()
                    else:
                        print("密码错误")
            if c == 0:
                print("账号错误")
        else:
            print("退出")
            break


main1()
